package tp2;

import java.util.Observable;
import java.util.Observer;

public class Circuit implements Observer{
private boolean terminee;
private Kart[] karts ;
private Team t;

public Circuit() {
	karts = new Kart[4];
}

private void init() {
	for (int i = 0; i < karts.length; i++) {
		karts[i] = new Kart("kart "+i, 1000, 0);
		karts[i].addObserver(this);
		Thread t = new Thread(karts[i]);
		t.setPriority(Thread.MIN_PRIORITY);
		t.start();
	}
	
}
public void courseTeam(){
	 t = new Team("Equipe 1");
	 t.start();
}

@Override
public void update(Observable o, Object arg) {
	stop((Kart) o);
	
	
}

public static void main(String[] args) {
	Circuit c = new Circuit();
	c.courseTeam();
	
}
public void resultat(){
	for (int i = 0; i < karts.length; i++) {
		System.out.println(karts[i].getNom() + " : " + karts[i].getDistance_parcouru());
	}
}
private void stop(Kart k) {
	for (int i = 0; i < karts.length; i++) {
		Kart kart = karts[i];
		if (kart != null && !kart.equals(k)){
			kart.setRunning(false);
			
		}
	}

}

}
